package com.ruoyi.mall.front.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.entity.MallAddress;
import com.ruoyi.mall.entity.MallLevel;
import com.ruoyi.mall.entity.MallMembers;
import com.ruoyi.mall.service.IMallAddressService;
import com.ruoyi.mall.service.IMallMembersService;
import com.ruoyi.system.domain.SysConfig;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 会员地址Controller
 * 
 * @author ruoyi
 * @date 2020-05-16
 */
@RestController
@RequestMapping("/mall/front/address")
public class FrontAddressController extends BaseController
{

    @Autowired
    private IMallAddressService mallAddressService;

    @GetMapping("/{phone}")
    public AjaxResult address(@PathVariable("phone") String phone)
    {
        List<MallAddress> mallAddresses = mallAddressService.selectAddressByPhone(phone);
        return AjaxResult.success(mallAddresses);
    }

    /**
     * 新增保存会员地址
     */
    @Log(title = "会员地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave( @RequestBody MallAddress mallAddress)
    {
        return toAjax(mallAddressService.insertMallAddress(mallAddress));
    }


    /**
     * 修改会员地址
     */
    @GetMapping("/edit/{addressId}")
    public AjaxResult edit(@PathVariable("addressId") Long addressId)
    {
        MallAddress mallAddress = mallAddressService.selectMallAddressById(addressId);
        return AjaxResult.success(mallAddress);
    }

    /**
     * 修改保存会员地址
     */
    @Log(title = "会员地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave( @RequestBody MallAddress mallAddress)
    {
        return toAjax(mallAddressService.updateMallAddress(mallAddress));
    }

    /**
     * 删除会员地址
     */
    @Log(title = "会员地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mallAddressService.deleteMallAddressByIds(ids));
    }
}
